package engine;

import java.util.*;

public class Level 
{
	private int height, width, level[][], entityLength, indexTemp;
	private ArrayList<AbstractEntity> entityList;
	private boolean a;
	BlockType blockType;
	
	public Level(int widthTemp, int heightTemp)
	{
		height = heightTemp;
		width = widthTemp;
		level = new int[heightTemp][widthTemp];
		entityList = new ArrayList<AbstractEntity>();
		indexTemp = 0;
		a = false;
		blockType = new BlockType();
	}
	
	public Level(int levelTemp[][])
	{
		width = levelTemp.length;
		height = levelTemp[0].length;
		level = levelTemp;
		entityList = new ArrayList<AbstractEntity>();
		indexTemp = 0;
		a = false;
		blockType = new BlockType();
	}
	
	public void generateLevel()
	{
		for(int i = 0; i < width; i++)
		{
			for(int j = 0; j < height/2; j++)
			{
				level[i][j] = -1;
			}
		}
		for(int i = 0; i < width; i++)
		{
			for(int j = height/2; j < height; j++)
			{
				level[i][j] = 0;
			}
		}
	}
	
	public int[][] getLevel()
	{
		return level;
	}
	
	public int getTile(int xTemp, int yTemp)
	{
		return level[xTemp][yTemp];
	}
	
	public int getTileS(int xTemp, int yTemp)
	{
		if(xTemp > width - 1 || xTemp < 0 || yTemp > height -1 || yTemp < 0)
		{
			System.out.println("ERROR - Out of Bounds of Level: Could not get tile at: " + xTemp + ", " + yTemp);
			return 0;
		}
		return level[xTemp][yTemp];
	}

	public void setTile(int xTemp, int yTemp, int setTemp)
	{
		level[xTemp][yTemp] = setTemp;
	}
	
	public void setTileS(int xTemp, int yTemp, int setTemp)
	{
		if(xTemp > width - 1 || xTemp < 0 || yTemp > height - 1 || yTemp < 0)
		{
			System.out.println("ERROR - Out of Bounds of Level: Could not set tile at: " + xTemp + ", " + yTemp);
			return;
		}
		level[xTemp][yTemp] = setTemp;
	}
	
	public boolean getCollidableTile(int blockTemp)
	{
		a = blockType.checkCollidable(blockTemp);
		return a;
	}
	
	public int getLevelHeight()
	{
		return height;
	}
	
	public int getLevelWidth()
	{
		return width;
	}
	
	public int getEntityLength()
	{
		return entityList.size();
	}
	
	public void setEntityLength(int entityLengthTemp)
	{
		entityList.ensureCapacity(entityLengthTemp);
	}
	
	public void addEntity(AbstractEntity entityTemp)
	{
		entityList.add(entityTemp);
	}
	
	public void removeEntity(AbstractEntity entityTemp)
	{
		indexTemp = 0;
		for(int i = 0; i < entityList.size(); i++)
		{
			if(entityList.get(i).equals(entityTemp))
			{
				entityList.remove(i);
			}
		}
	}
	
	public List<AbstractEntity> getEntities()
	{
		return entityList;
	}
	
	public AbstractEntity getEntity(int tempIndex)
	{
		return entityList.get(tempIndex);
	}
}
//test